/**
 * 常用方法的独立实现包
 * @email 710335997@qq.com
 */
var mj={

    /**
     * 解析url获取query参数
     * @param url
     * @returns {object}
     * @example
     * var url="http://www.baidu.com?w=2";
     * var data=mj.querys(url) // ->{w:2};
     */
    querys(url){
        var result = {},
            keyReg = /(\?(.*?)=|&(.*?)=)/g,
            valReg = /=(.*?)&/g,
            urls = url ? (url + "&") : "",
            keys = urls.match(keyReg) || [],
            vals = urls.match(valReg) || [];
        for (var i = 0, size = keys.length; i < size; i++) {
            result[keys[i].replace(/(\?|=|&)/g, '')] = vals[i].replace(/(=|&)/g, '');
        }
        return result;
    },

    /**
     * 对象深拷贝
     * @param out
     * @returns {}
     */
    deepExtend(out){
        out = out || {};
        for (var i = 1; i < arguments.length; i++) {
            var obj = arguments[i];

            if (!obj)
                continue;

            for (var key in obj) {
                if (obj.hasOwnProperty(key)) {
                    if (typeof obj[key] === 'object')
                        out[key] = mj.deepExtend(out[key], obj[key]);
                    else
                        out[key] = obj[key];
                }
            }
        }

        return out;
    },
    /**
     * 对象浅拷贝
     * @param out
     * @returns {Object}
     */
    extend(out){
        out = out || {};

        for (var i = 1; i < arguments.length; i++) {
            if (!arguments[i])
                continue;

            for (var key in arguments[i]) {
                if (arguments[i].hasOwnProperty(key))
                    out[key] = arguments[i][key];
            }
        }

        return out;
    },

    /**
     * 检查数据对象类型
     * @param {Object} obj
     * @returns {String} 数据类型,如：array string number boolean
     */
    type(obj){
        Object.prototype.toString.call(obj).replace(/^\[object (.+)\]$/, '$1').toLowerCase();
    }
}

export default mj